<template>
	<view>
		<u-toast ref="uToast"></u-toast>
		<!-- 买家 -->
		<view class="goshop-order-list-footer" v-if="mode===0">
			<view class="goshop-order-list-footer-left" @tap="contactSellor()">
				<view class="iconfont iconfont-comment"></view>
				<view class="goshop-order-list-footer-left-text">
					{{contactbuyerText}}
				</view>
			</view>
			<view class="goshop-order-list-footer-right">
				<u-button v-if="order.status === 10" @click="goPayPage()" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="topayText"></u-button>
				<u-button v-if="order.status === 10" @click="doOrderCancel()" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="cancelorderText"></u-button>
				<u-button v-if="order.status === 11" @click="goSalePage()" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="toreturnText"></u-button>
				<u-button v-if="order.status === 5 || order.status === 100" @click="doOrderDelete()" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="deleteorderText"></u-button>
				<u-button v-if="order.status === 12" @click="showConfirm = true" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="confirmdeliveryText"></u-button>
				<u-button v-if="order.status === 13" @click="goEvaluatePage()" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="toevaluateText"></u-button>
				<!-- <u-button v-if="order.status === 14" @click="goSaleInfoPage()" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="aftersaledetailsText"></u-button> -->
			</view>
		</view>
		<!-- 卖家 -->
		<view class="goshop-order-list-footer" v-else>
			<view class="goshop-order-list-footer-left" @tap="contactBuyer()">
				<view class="iconfont iconfont-comment"></view>
				<view class="goshop-order-list-footer-left-text">
					{{contactsellorText}}
				</view>
			</view>
			<view class="goshop-order-list-footer-right">
				<u-button class="operate-btn" @click="showUpdatePrice = true" v-if="order.status === 10" shape="circle" size="small" :hairline="true" :plain="true" :text="changepriceText"></u-button>
				<u-button class="operate-btn" @click="goShipPage()" v-if="order.status === 11" shape="circle" size="small" :hairline="true" :plain="true" :text="toshipText"></u-button>
				<!-- <u-button v-if="order.status === 14" @click="goSaleHandlePage()" class="operate-btn" shape="circle" size="small" :hairline="true" :plain="true" :text="aftersalehandleText"></u-button> -->
			</view>
		</view>
		<u-action-sheet :actions="cancelDataList" @close="selectCancelClose" :title="cancelTitle" @select="selectCancelClick" :show="showCancel" :closeOnClickOverlay="true" :closeOnClickAction="true" ></u-action-sheet>
		<u-modal
			:title="receivedyetText"
			:confirmText="confirmText"
			:cancelText="cancelText"
			:show="showConfirm"
			@close="showConfirm = false"
			closeOnClickOverlay
			@confirm="doConfirm()"
		>
		  <view class="row-y row-cen">
			  <image
			  	style="width: 80px;height: 80px;"
			  	:src="order.goodInfo.thumbnail"
			  ></image>
			  <view>
			  	{{aftersalerightsText}}
			  </view>
		  </view>
		</u-modal>
		<u-modal
			:show="showUpdatePrice"
			:confirmText="confirmText"
			:cancelText="cancelText"
			:title="fillorderpriceText"
			showCancelButton
			closeOnClickOverlay
			@confirm="doUpdatePriceConfirm"
			@cancel="showUpdatePrice = false"
			@close="showUpdatePrice = false"
		>
		 <u--input
		    :placeholder="fillpriceText"
		    border="surround"
		    v-model="price"
		  ></u--input>
		</u-modal>
	</view>
</template>

<script>
	import {orderCancel,orderConfirm,orderDelete} from '@/common/http.api.js'
	export default {
		name:"goshop-order-operate",
		data() {
			return {
				fillorderpriceText:'',
				reasoncancellationText:'',
				goodsreceivedText:'',
				topayText:'',
				receivedyetText:'',
				confirmdeliveryText:'',
				deleteorderText:'',
				toevaluateText:'',
				changepriceText:'',
				pricechangedText:'',
				contactsellorText:'',
				applyaftersalesText:'',
				contactbuyerText:'',
				toshipText:'',
				cancelorderText:'',
				toreturnText:'',
				fillpriceText:'',
				deletedsuccText:'',
				aftersalerightsText:'',
				aftersaledetailsText:'',
				aftersalehandleText:'',
				calsuccText:'',
				cancelDataList:[],
				cancelTitle: this.reasoncancellationText,
				showCancel:false,
				showConfirm:false,
				price:null,
				//显示修改价格
				showUpdatePrice:false,
				confirmText:'',
				cancelText:'',
			};
		},
		props: {
		  //订单数据
		  order:{
				type:Object,
				default:{
					status:1
				}
		  },
		  //0 买家 1 卖家
		  mode:{
			   type:Number,
			   default: 0
		  },
		  //0 买到 1 卖出
		  type:{
			   type:Number,
			   default: 0
		  }
		},
		created() {
		  this.refresh();	
		},
		methods:{
			refresh(){
				this.fillorderpriceText = this.$t('order.fillorderprice.text');
				this.reasoncancellationText = this.$t('order.reasoncancellation.text');
				this.goodsreceivedText = this.$t('order.goodsreceived.text');
				this.topayText = this.$t('order.topay.text');
				this.receivedyetText = this.$t('order.receivedyet.text');
				this.confirmdeliveryText = this.$t('order.confirmdelivery.text');
				this.deleteorderText = this.$t('order.deleteorder.text');
				this.toevaluateText = this.$t('order.toevaluate.text');
				this.changepriceText = this.$t('order.changeprice.text');
				this.pricechangedText = this.$t('order.pricechanged.text');
				this.contactsellorText = this.$t('order.contactsellor.text');
				this.applyaftersalesText = this.$t('order.applyaftersales.text');
				this.contactbuyerText = this.$t('order.contactbuyer.text');
				this.toshipText = this.$t('order.toship.text');
				this.cancelorderText = this.$t('order.cancelorder.text');
				this.toreturnText = this.$t('order.toreturn.text');
				this.fillpriceText = this.$t('order.fillprice.text');
				this.deletedsuccText = this.$t('order.deletedsucc.text');
				this.aftersalerightsText = this.$t('order.aftersalerights.text');
				this.calsuccText = this.$t('order.calsucc.text');
				this.aftersaledetailsText = this.$t('order.aftersaledetails.text');
				this.aftersalehandleText = this.$t('order.aftersalehandle.text');
				this.confirmText = this.$t('common.sure.text');
				this.cancelText = this.$t('common.cancel.text');
			},
			//售后处理
			goSaleHandlePage(){
				let page = '/pages/common/return/refund';
				//判断售后类型
				let orderAfter = this.order.orderAfterInfo;
				if(orderAfter.type === 2){
					page = '/pages/common/return/refunds';
				}else if(orderAfter.type === 3){
					page = '/pages/common/return/exchange';
				}
				//在起始页面跳转到test.vue页面并传递参数
				uni.navigateTo({
					url: page + '?id='+orderAfter.id+'&mode=1&edit=0'
				});
			},
			//售后详情
			goSaleInfoPage(){
				let page = '/pages/common/return/refund';
				//判断售后类型
				let orderAfter = this.order.orderAfterInfo;
				if(orderAfter.type === 2){
					page = '/pages/common/return/refunds';
				}else if(orderAfter.type === 3){
					page = '/pages/common/return/exchange';
				}
				//在起始页面跳转到test.vue页面并传递参数
				uni.navigateTo({
					url: page + '?id='+orderAfter.id+'&mode=0&edit=0'
				});
			},
			//联系买家
			contactSellor(){
				uni.navigateTo({
					url: '/pages/common/chat/chat?conversationID=C2C' + this.order.memberId + '&chatMode=2'
				})
			},
			//联系卖家
			contactBuyer(){
				uni.navigateTo({
					url: '/pages/common/chat/chat?conversationID=C2C' + this.order.merchantId + '&chatMode=2'
				})
			},
			goShipPage(){
				uni.navigateTo({
					url: '/pages/common/order/ship?id='+this.order.id
				});
			},
			doUpdatePriceConfirm(){
				let that = this;
				orderPrice({params: {id:this.order.id,price:this.price}}).then(res => {
					if (res.code === 0) {
						this.order.status = 3;
						uni.hideLoading();
						this.$refs.uToast.show({
							message: that.pricechangedText,
							type: 'success',
						})
					} else {
						uni.hideLoading();
						this.$refs.uToast.show({
							message: res.msg,
							type: 'error',
						})
					}
				});
			},
			goEvaluatePage(){
				uni.navigateTo({
					url: '/pages/common/order/evaluate?orderId='+this.order.id + '&orderGoodId=' + this.order.orderGoodInfo.id
				});
			},
			doConfirm(){
				let that = this;
				orderConfirm({params: {id:this.order.id}}).then(res => {
					if (res.code === 0) {
						this.order.status = 3;
						this.showConfirm = false;
						uni.hideLoading();
						this.$refs.uToast.show({
							message: that.goodsreceivedText,
							type: 'success',
						})
					} else {
						this.showConfirm = false;
						uni.hideLoading();
						this.$refs.uToast.show({
							message: res.msg,
							type: 'error',
						})
					}
				});
			},
			doOrderDelete(){
				let that = this;
				orderDelete({params: {id:this.order.id}}).then(res => {
					if (res.code === 0) {
						this.order.status = 101;
						uni.hideLoading();
						this.$refs.uToast.show({
							message: that.deletedsuccText,
							type: 'success',
						})
					} else {
						uni.hideLoading();
						this.$refs.uToast.show({
							message: res.msg,
							type: 'error',
						})
					}
				});
			},
			selectCancelClose(){
				
			},
			selectCancelClick(){
				
			},
			goSalePage(){
				uni.navigateTo({
					url: '/pages/common/return/sale?id='+this.order.id
				});
			},
			goPayPage(){
				uni.navigateTo({
					url: '/pages/common/order/pay?id='+this.order.id
				});
			},
			doOrderCancel(){
				debugger
				let that = this;
				orderCancel({params: {id:this.order.id}}).then(res => {
					if (res.code === 0) {
						this.order.status = 50;
						uni.hideLoading();
						this.$refs.uToast.show({
							message: that.calsuccText,
							type: 'success',
						})
					} else {
						uni.hideLoading();
						this.$refs.uToast.show({
							message: res.msg,
							type: 'error',
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss">
.operate-btn{
	margin-left: 20rpx;
}
.goshop-order-list-footer{
   padding: 20rpx;
   display: flex;
   align-items: center;
   justify-content: space-between;
   .goshop-order-list-footer-left{
	   display: flex;
	   flex: 3;
	   align-items: center;
	   .goshop-order-list-footer-left-text{
		   padding-left: 20rpx;
	   }
   }
   .goshop-order-list-footer-right{
	   display: flex;
	   justify-content: flex-end;
	   align-items: center;
   }
}
</style>